//*************************************************************************************
//* 作    者： z hunter
//* 创建时间： 2021-09-23 08:11:33
//* 描    述： 本地化

//* ************************************************************************************
using UnityEngine;
using UFrame.Texts;

public class LanguageAgent : AgentContext<LanguageAgent, LocalizationCtrl>
{
    public static void UseLocalizationCfg2(int language)
    {
        var localizationCfg = TableAgent.Instance.localization_cfgTable;
        using (var enumerator = localizationCfg.GetListEnumerator())
        {
            while (enumerator.MoveNext())
            {
               var current = enumerator.Current;
               Instance.MakeKeyIndex(current.key, current.id);
               Instance.SetText(current.ID, current.cn, (int)SystemLanguage.Chinese);
               Instance.SetText(current.ID, current.en, (int)SystemLanguage.English);
            }
        }
        localizationCfg.Clear();
        Instance.SwitchLanguage(language, true);
    }

    public static void UseLocalizationCfg4(int language)
    {
        var localizationCfg = TableAgent.Instance.localization_cfgTable;
        using (var enumerator = localizationCfg.GetListEnumerator())
        {
            while (enumerator.MoveNext())
            {
                var current = enumerator.Current;
                Instance.MakeKeyIndex(current.key, current.id);
                Instance.SetText(current.ID, current.cn, (int)SystemLanguage.Chinese);
                Instance.SetText(current.ID, current.en, (int)SystemLanguage.English);
                Instance.SetText(current.ID, current.jp, (int)SystemLanguage.Japanese);
                Instance.SetText(current.ID, current.tw, (int)SystemLanguage.ChineseTraditional);
            }
        }
        localizationCfg.Clear();
        Instance.SwitchLanguage(language, true);
    }

    public static bool SetLanguage(SystemLanguage language)
    {
        var languageId = (int)language;
        if (!Instance.ExistLanguage(languageId))
            return false;
        Instance.SwitchLanguage(languageId);
        return true;
    }

    public static string GetText(int textId)
    {
        return Instance.GetText(textId);
    }

    public static string GetText(string textKey)
    {
        return Instance.GetTextByKey(textKey);
    }
}